package com.zlp.partice.io.channel;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

/**
 * @author: zhulaiping
 * @time: 2022/8/18 15:40
 */
public class FileChannelDemo1 {

    public static void main(String[] args) throws IOException {
        FileChannel from = new FileInputStream("data.txt").getChannel();
        FileChannel to = new FileOutputStream("to.txt").getChannel();
        //效率高，底层使用操作系统的零拷贝优化，但大小有限制，不能超过两g
        //from.transferTo(0,from.size(),to);
        long size = from.size();
        for(long left = size;left>0;){
            from.transferTo(0,from.size(),to);

        }
    }
}
